using Blog2025.Application.Common;
using Blog2025.Application.Dto;
using Blog2025.Application.Services;
using Microsoft.AspNetCore.Mvc;

namespace Blog2025.Api.Controllers;
[ApiController]
[Route("api/[controller]")]
public class DepartmentController:ControllerBase
{
    private readonly IDepartmentAppServices _service;
    public DepartmentController(IDepartmentAppServices service)
    {
        _service=service;
    }
    // 创建部门
    [HttpPost]
    public async Task<IActionResult> Create(CreateDepartmentDto dto)
    {
        await _service.CreateDepartmentAsync(dto);
        return Ok("创建成功");
    }
    // 删除部门 
    [HttpDelete("{id}")]
    public async Task<IActionResult> Delete(Guid id)
    {
        await _service.DeleteDepartmentAsync(id);
        return Ok("删除成功");
    }
    // 修改部门 
    [HttpPut("{id}")]
    public async Task<IActionResult> Update(Guid id,CreateDepartmentDto dto)
    {
        await _service.UpdateDepartmentAsync(id,dto.DepartmentName);
        return Ok("修改成功");
    }
    // 获取部门 
    [HttpGet]
    public async Task<ApiResult> GetAll(PageRequestDto pageRequestDto)
    {
        var dep=await _service.GelAllDepartmentAsync(pageRequestDto);
        return ApiResult.Success(dep);
    }
    
    [HttpGet("filter")]
    public async Task<IActionResult>  GetFilter()
    {
        var filters=new Dictionary<string,object>
        {
            {"departmentName","人事部"}
        };
        var res=await _service.GetFilterAsync(filters);
        return Ok(res);
    }

    // 获取部门 
    [HttpGet("{id}")]
    public async Task<IActionResult> GetById(Guid id)
    {
        var dep=await _service.GelByIdDepartmentAsync(id);
        return Ok(dep);
    }
}